define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_refund/index' + location.search,
                    add_url: 'order_refund/add',
                    edit_url: 'order_refund/edit',
                    del_url: 'order_refund/del',
                    multi_url: 'order_refund/multi',
                    import_url: 'order_refund/import',
                    table: 'order_refund',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'reason', title: __('Reason'), operate: 'LIKE'},
                        // {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        //类型:0=爆品,1=捐增,2=兑换
                        {field: 'type', title: __('Type'),searchList: {"0":__('爆品'),"1":__('捐增'),"2":__('兑换')},formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('类型'),searchList: {"1":__('申请中'),"2":__('已通过'),"3":__('已打款'),"-1":__('拒绝')},formatter: Table.api.formatter.normal},
                        // {field: 'desc', title: __('Desc'), operate: 'LIKE'},
                        {field: 'types', title: __('退款类型'),searchList: {"1":__('退货退款'),"2":__('退款')},formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.sell_id', title: __('Order.sell_id')},
                        {field: 'order.order_sn', title: __('Order.order_sn'), operate: 'LIKE'},
                        {field: 'order.pay_price', title: __('Order.pay_price'), operate:'BETWEEN'},
                        // {field: 'order.mode', title: __('Order.mode')},
                        // {field: 'order.status', title: __('Order.status'), formatter: Table.api.formatter.status},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'orderaddress.name', title: __('Orderaddress.name'), operate: 'LIKE'},
                        {field: 'orderaddress.phone', title: __('Orderaddress.phone')},
                        // {field: 'orderaddress.province', title: __('Orderaddress.province'), operate: 'LIKE'},
                        // {field: 'orderaddress.city', title: __('Orderaddress.city'), operate: 'LIKE'},
                        // {field: 'orderaddress.area', title: __('Orderaddress.area'), operate: 'LIKE'},
                        // {field: 'orderaddress.address', title: __('Orderaddress.address'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'order_refund/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'order_refund/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'order_refund/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});